Array.prototype.reduce2 = function (fn, initial) {
    if (typeof fn !== 'function') {
        throw new TypeError(`${fn} is not a function`)
    }
    let accumulate, currenIndex = -1
    if (arguments.length === 2) {
        currenIndex = 0
        accumulate = initial
    } else {
        for (let i = 0; i < this.length; i++) {
            if (this.hasOwnProperty(i)) {
                accumulate = this[i]
                currenIndex = i+1
                break//注意这里是break 不是return
            }
        }
    }

    if (currenIndex === -1) {
        throw new TypeError(`${this} is a empty Array`)
    }

    for (let i = currenIndex; i < this.length; i++) {
        if (this.hasOwnProperty(i)) {
            accumulate=fn(accumulate,this[i],i,this)
        }
    }
    return accumulate
}

let arr=[1,5]
console.log(arr.reduce2((a,b)=>a+b));